﻿Imports System.Data.OleDb


Public Class AddHotel
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"

        If f_picture.HasFile Then
            Dim picLocationOnHD = Request.MapPath("pictures") & "/" & newFileName
            f_picture.SaveAs(picLocationOnHD)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("FoodConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into food(FoodName,FoodDescription,FoodBestBefore,FoodOriginalPriceCurrency,FoodPicture,FoodUser,FoodBrand,FoodSize,InExchangeFor) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)

        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_FoodName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_FoodDescription.Text)
        cmd.Parameters.AddWithValue("@f3", cl_BestBefore.SelectedDate)
        cmd.Parameters.AddWithValue("@f4", tb_OriginalPrice.Text)
        cmd.Parameters.AddWithValue("@f5", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f6", User.Identity.Name)
        cmd.Parameters.AddWithValue("@f7", tb_FoodBrand.Text)
        cmd.Parameters.AddWithValue("@f8", tb_FoodSize.Text)
        cmd.Parameters.AddWithValue("@f9", tb_InExchange.Text)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub


    Protected Sub Validate_Numeric(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
        Dim r As New System.Text.RegularExpressions.Regex("^[0-9]+$")
        e.IsValid = r.IsMatch(tb_OriginalPrice.Text)
    End Sub




End Class